﻿namespace CodeAgent.Host.Context;

public class AgentContext
{
    private static readonly AsyncLocal<AgentContextHolder> _agentContextCurrent = new();

    public static AgentContextStorage? Current
    {
        get => _agentContextCurrent.Value?.Storage;
        set
        {
            var httpContextHolder = _agentContextCurrent.Value;
            if (httpContextHolder != null)
                httpContextHolder.Storage = null;
            if (value == null)
                return;
            _agentContextCurrent.Value = new AgentContextHolder()
            {
                Storage = value
            };
        }
    }

    internal sealed class AgentContextHolder
    {
        public AgentContextStorage? Storage { get; set; } = new();
    }
}